package com.haredot.exception;

import com.haredot.interceptor.exception.IpRateException;
import com.haredot.vo.R;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(IpRateException.class)
    public R<?> ipRateException(IpRateException exception) {
        return R.fail(R.StatusCode.FORBIDDEN, exception.getMessage()).build();
    }

    @ExceptionHandler(Exception.class)
    public R<?> exception(Exception exception) {
        exception.printStackTrace();
        return R.fail(R.StatusCode.ERROR, exception.getMessage()).build();
    }
}
